//
//  JKNavigationController.swift
//  新浪微博
//
//  Created by Jack.Lin on 16/6/29.
//  Copyright © 2016年 Jack.Lin. All rights reserved.
//

import UIKit

class JKNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
    }
    
    // 重写 push 方法, 所有的 push 都会调用此方法!!!
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
        
            if let vc = viewController as? JKBaseViewController {
                
                var title = "返回"
                
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent), isBack: true)
            }
        
        }
        super.pushViewController(viewController, animated: true)
    }

    @objc private func popToParent() {
    
       popViewController(animated: true)
    }
   
}
